package com.xbongbong.paas.help.subform;

import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.help.subform.abstracts.AbstractUserAndDepTeamTransferSubForm;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.domain.entity.UserAndDepTeamEntity;
import com.xbongbong.saas.domain.entity.UserTeamEntity;
import com.xbongbong.saas.domain.entity.WarehouseUserEntity;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 仓库 es和数据库格式转化
 * @author 魏荣杰
 *
 */
@Component
public class WarehouseTeamTransferSubForm extends AbstractUserAndDepTeamTransferSubForm {

    @Override
    public PaasFormDataEntity transferTeamToFormData(UserAndDepTeamEntity userAndDepTeamEntity) {

        return null;
    }

    @Override
    public UserAndDepTeamEntity transferFormDataToTeam(PaasFormDataEntity paasFormDataEntity) {

        return null;
    }

    /**
     * 仓库团队List实体转userTeam
     * @param warehouseUserEntityList
     */
    public List<UserTeamEntity> transferWarehouseUserToUserTeam(List<WarehouseUserEntity> warehouseUserEntityList) {
        List<UserTeamEntity> userTeamEntityList = new ArrayList<>();
        if (CollectionsUtil.isNotEmpty(warehouseUserEntityList)){
            for (WarehouseUserEntity entity : warehouseUserEntityList){
                UserTeamEntity userTeamEntity = new UserTeamEntity();
                userTeamEntity.setId(entity.getId());
                userTeamEntity.setUserId(entity.getRelationId());
                userTeamEntity.setUserName(entity.getRelationName());
                userTeamEntity.setDataId(entity.getDataId());
                userTeamEntity.setCorpid(entity.getCorpid());
                userTeamEntity.setIsMain(BasicConstant.ONE);
                userTeamEntityList.add(userTeamEntity);
            }
        }
        return userTeamEntityList;
    }

    /**
     * userTeamList转仓库团队实体
     * @param userTeamEntityList
     */
    public List<WarehouseUserEntity> transferUserTeamUserToWarehouseUser(List<UserTeamEntity> userTeamEntityList){
        List<WarehouseUserEntity> warehouseUserEntityList = new ArrayList<>();
        if (CollectionsUtil.isNotEmpty(userTeamEntityList)){
            for (UserTeamEntity entity : userTeamEntityList){
                WarehouseUserEntity warehouseUserEntity = new WarehouseUserEntity();
                warehouseUserEntity.setId(entity.getId());
                warehouseUserEntity.setRelationId(entity.getUserId());
                warehouseUserEntity.setRelationName(entity.getUserName());
                warehouseUserEntity.setDataId(entity.getDataId());
                warehouseUserEntity.setCorpid(entity.getCorpid());
                warehouseUserEntity.setType(BasicConstant.ZERO);
                warehouseUserEntityList.add(warehouseUserEntity);
            }
        }
        return warehouseUserEntityList;
    }
}
